' Test ab ...and 1 for the monkey.txt rev for SB.exe convert 2021-02-20
' from ... and 1 for the monkey problem.bas for JB 2.0 b 2018-02-11
' Completely rewritten 2021-02-21. 

people = 3
nutStart = 100
[
	. /          ... and one for the Monkey
	.
	. / There are ;people; people and 1 monkey on an island.
	. / Yesterday the amount of coconuts they collect is ; nutStart
	' track nut inventory with: nutsnow
	. / Last night, each person goes to the pile, takes a divy
	. / gives 1 coconut to the monkey and hides the remaining.
	. /  (No coconuts are cut into parts in this problem.)
	.
	p = 0
	monkey = 0
	nutsNow = nutStart
	[
		p = a[p,1]
		Jmp gt[p,People]
		divy = Int[d[nutsNow,People]]
		If gte[divy,1]
			nutsNow = s[nutsnow,divy]
			monkey = a[monkey,1]
			divy = s[divy,1]
		Fi
		'wth next line
		divy = a[divy,0]
		Set piles;p;divy
		. / For person ;p;/ their pile is ; divy; coconut(s).
	]
	. / So the remaining coconuts after last night is ;nutsNow
	. /                        ... and the monkey has ;monkey
	.
	. / This morning, they give the monkey a coconut and divide 
	. / the remaining pile by number of people, what is the size 
	. / of everyone's pile?
	.
	. / Coconuts starting today is ; nutsNow
	If gt[nutsNow,0] 
		monkey = a[monkey,1]
		nutsNow = s[nutsNow,1]
	Fi
	divy = Int[d[nutsNow,People]]
	. / So each person gets ; divy;/ more coconuts.
	p = 0
	[ 
		p = a[p,1]
		Jmp gt[p,People]
		curr = get[piles,p]
		total = a[curr,divy]
		. / Person ;p; had hidden ;curr; and gets ;divy; so has ; total
		nutsnow = s[nutsNow,divy]
	]
	. / The monkey has ; monkey;/ coconuts.
	. / There remains ; nutsNow; nuts for this author.
	.
	nutstart = s[NutStart,10]
	If gt[nutStart,0]
		Loc 34;5
		. ZZZ... press any to see day with 10 less coconuts to start
		Zzz
		Cls
	El
		Exit
	Fi
]
. /            Good bye!
End